# 一、环境
# 1.1 系统信息
**操作系统:**MacOS Monterey 12.2.1
**芯片:**Apple M1 Pro
# 1.2 软件信息
**软件:**Docker DeskTop 4.6.0、Final Shell 3.9.2.2
# 1.3 镜像信息
**IMAGE:**Nacos
**TAG:**latest
# 二、安装
# 2.1 拉取镜像
由于M1 不支持高版本nacos,所以需要拉取特定的版本
docker pull zhusaidong/nacos-server-m1:2.0.3

# 2.2 创建容器
docker run --env MODE=standalone --name nacos -d -p 8848:8848 -p 9848:9848 -p 9849:9849 zhusaidong/nacos-server-m1:2.0.3

# 2.2.3 命令详解
run:表示运行容器
-d: -d表示后台运行
-p: -p表示宿主机端口与Docker容器端口映射
--name:为容器指定一个名称
# 2.2.4 第一次测试
访问 http://localhost:8848/nacos
# 2.3 进入容器
格式:docker exec -it 容器名|容器ID bash
#进入容器
docker exec -it nacos bash
# 2.3.1 创建nacos数据库
在你的MySQL,创建数据库nacos_config。
然后去github上获取SQL【nacos的Sql文件 (opens new window)】,再导入SQL即可。
# 2.3.2 配置数据库
# 查看容器中的文件
ls -l
# 进入到conf
cd conf
# 编辑配置文件
vim application.properties
更改MySQL连接四要素,地址、库、账号、密码,值得注意的一点,我用的是MySQL容器,所以需要把地址改成host.docker.internal
自动匹配宿主机数据库

修改前的application.properties文件
# spring
server.servlet.contextPath=${SERVER_SERVLET_CONTEXTPATH:/nacos}
server.contextPath=/nacos
server.port=${NACOS_APPLICATION_PORT:8848}
spring.datasource.platform=${SPRING_DATASOURCE_PLATFORM:""}
nacos.cmdb.dumpTaskInterval=3600
nacos.cmdb.eventTaskInterval=10
nacos.cmdb.labelTaskInterval=300
nacos.cmdb.loadDataAtStart=false
db.num=${MYSQL_DATABASE_NUM:1}
db.url.0=jdbc:mysql://${MYSQL_SERVICE_HOST}:${MYSQL_SERVICE_PORT:3306}/${MYSQL_SERVICE_DB_NAME}?${MYSQL_SERVICE_DB_PARAM:characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false}
db.url.1=jdbc:mysql://${MYSQL_SERVICE_HOST}:${MYSQL_SERVICE_PORT:3306}/${MYSQL_SERVICE_DB_NAME}?${MYSQL_SERVICE_DB_PARAM:characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false}
db.user=${MYSQL_SERVICE_USER}
db.password=${MYSQL_SERVICE_PASSWORD}
### The auth system to use, currently only 'nacos' is supported:
nacos.core.auth.system.type=${NACOS_AUTH_SYSTEM_TYPE:nacos}
### The token expiration in seconds:
nacos.core.auth.default.token.expire.seconds=${NACOS_AUTH_TOKEN_EXPIRE_SECONDS:18000}
### The default token:
nacos.core.auth.default.token.secret.key=${NACOS_AUTH_TOKEN:SecretKey012345678901234567890123456789012345678901234567890123456789}
### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.
nacos.core.auth.caching.enabled=${NACOS_AUTH_CACHE_ENABLE:false}
nacos.core.auth.enable.userAgentAuthWhite=${NACOS_AUTH_USER_AGENT_AUTH_WHITE_ENABLE:false}
nacos.core.auth.server.identity.key=${NACOS_AUTH_IDENTITY_KEY:serverIdentity}
nacos.core.auth.server.identity.value=${NACOS_AUTH_IDENTITY_VALUE:security}
server.tomcat.accesslog.enabled=${TOMCAT_ACCESSLOG_ENABLED:false}
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
# default current work dir
server.tomcat.basedir=
## spring security config
### turn off security
nacos.security.ignore.urls=${NACOS_SECURITY_IGNORE_URLS:/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**}
# metrics for elastic search
management.metrics.export.elastic.enabled=false
management.metrics.export.influx.enabled=false
nacos.naming.distro.taskDispatchThreadCount=10
nacos.naming.distro.taskDispatchPeriod=200
nacos.naming.distro.batchSyncKeyCount=1000
nacos.naming.distro.initDataRatio=0.9
nacos.naming.distro.syncRetryDelay=5000
nacos.naming.data.warmup=true
# 2.4 重启容器
#退出容器
exit
#重启容器
docker restart nacos

# 2.4.1 测试
访问 http://localhost:8848/nacos
初始账密nacos/nacos
